/*
 * Powered By [rapid-framework]
 * Csdn Code: generate simple CRUD code in single table.
 * Since 2015 - 2017
 */

BUI.use('common/page');
BUI.use([ 'common/search', 'bui/overlay', 'bui/grid', 'bui/data', 'bui/form','bui/select' ],
    function(Search, Overlay, Grid, Data, Form,Select) {
        // 查询表单
        var form = new Form.Form({
            srcNode : '#searchForm'
        }).render();
        // 定义表头
        columns = [ {
            title : '渠道名称',
            dataIndex : 'channelName',
            elCls : 'center',
            width : 200
        }, {
            title : '注册数',
            dataIndex : 'registerNum',
            elCls : 'center',
            width : 200
        }, {
            title : '放款数',
            dataIndex : 'loanAmount',
            elCls : 'center',
            width : 200
        },{
            title : '放款金额(人民币：元)',
            dataIndex : 'loanAmountNum',
            elCls : 'center',
            width : 400
        }, {
            title : '日期',
            dataIndex : 'statisticalStartTime',
            elCls : 'center',
            width : 200
        } ];
        // 获取表格对象
        gridCfg = Search.createGridCfg(columns, {
            tbar : {
                items : [{
                    btnCls : 'button button-small',
                    text : '<i class="icon-refresh"></i>刷新',
                    listeners : {
                        'click' : refreshFunction
                    }
                }]
            }
        });
        //渠道选择框
        var privileges = sessionStorage.getItem('channelData');
        var privilegeList = privileges.split(',');
        var items=[];
        for(var i=0;i<privilegeList.length-1;i++){
            var privilege=privilegeList[i].split('-');
            items[i]={text:privilege[1],value:privilege[0]};
        }
        var select = new Select.Select({
            render:'#channelData',
            valueField:'#channel',
            items:items
        });
        select.render();
        select.on('change', function(ev){
            //channel=ev.item;
        });
        // 获取数据
        store = new BUI.Data.Store({
            url : 'listChannelCount',
            pageSize : 20,
            autoLoad : true,
            remoteSort : true
        });

        search = new Search({
            width : '100%',// 这个属性一定要设置
            store : store,
            autoSearch : true,
            gridCfg : gridCfg
        });
        grid = search.get('grid');
        // 刷新
        function refreshFunction() {
            search.load();
        }
    });
